﻿namespace VirtualTemplates
{
    using System.Globalization;

    /// <summary>
    /// Helps to create a hash code.
    /// </summary>
    internal class HashCode
    {
        private int code;

        /// <summary>
        /// Initializes a new instance of the <see cref="HashCode"/> class.
        /// </summary>
        public HashCode()
        {
            this.code = 5381;
        }

        /// <summary>
        /// Adds a new hash code by combining it with this hash code.
        /// </summary>
        /// <param name="h">The new hash code.</param>
        public void Add(int h)
        {
            this.code = (this.code << 5) + this.code ^ h;
        }

        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <returns>
        /// A <see cref="System.String"/> that represents this instance.
        /// </returns>
        public override string ToString()
        {
            return this.code.ToString("x", CultureInfo.InvariantCulture);
        }
    }
}
